package com.yy.bolg.service.impl;

import com.yy.bolg.dao.FixedPointDao;
import com.yy.bolg.entity.FixedPointBean;
import com.yy.bolg.exception.LackParameterException;
import com.yy.bolg.exception.OtherThingsException;
import com.yy.bolg.service.FixedPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 附件分类Service实现类，对接口里的方法进行构造填充
 * @author enmaoFu
 * @date 2024-11-04
 */
@Service("fixedPointService")
public class FixedPointServiceImpl implements FixedPointService {

    @Autowired
    private FixedPointDao fixedPointDao;

    @Override
    public void add(FixedPointBean bean) throws Exception {
        try {
            fixedPointDao.add(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("添加数据失败");
        }
    }

    @Override
    public List<FixedPointBean> findAllToDateToDeviceId(FixedPointBean bean) throws Exception {
        if(StringUtils.isEmpty(bean.getPsFpDeviceId())){
            throw new LackParameterException("设备ID不能为空");
        }

        if(StringUtils.isEmpty(bean.getStartTime())){
            throw new LackParameterException("起始日期不能为空");
        }

        if(StringUtils.isEmpty(bean.getEndTime())){
            throw new LackParameterException("结束日期不能为空");
        }
        try {
            return fixedPointDao.findAllToDateToDeviceId(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new LackParameterException(e.getMessage());
        }
    }
}
